<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="产品:" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称:" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购买时间:" prop="mail">
        <el-date-picker
          v-model="queryParams.buyDate"
          type="daterange"
          clearable
          placeholder="日期区间选择"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item label="到期时间:" prop="mail">
        <el-date-picker
          v-model="queryParams.endDate"
          type="daterange"
          clearable
          placeholder="日期区间选择"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item label="订单状态:" prop="status">
        <el-select
          v-model="queryParams.status"
          clearable
          placeholder="请选择"
        >
          <el-option
            label="正常"
            value="NORMAL"
          />
          <el-option
            label="取消"
            value="CANCEL"
          />
          <el-option
            label="结束"
            value="END"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="walletMarketList" @selection-change="handleSelectionChange">
      <el-table-column label="产品名称" align="center" prop="name" />
      <el-table-column label="编号" align="center" prop="id" show-overflow-tooltip/>
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="金额" align="center" prop="amount" />
      <el-table-column label="购买时间" align="center" prop="startTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到期时间" align="center" prop="endTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="statusLabel" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.current"
      v-model:limit="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="WalletMarket">
import { listWalletMiningList } from "@/api/boot/walletMiningList";
import {parseTime} from "../../../utils/ruoyi.js";

const { proxy } = getCurrentInstance();

const walletMarketList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    current: 1,
    size: 10,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询市场买卖交易记录列表 */
function getList() {
  loading.value = true;
  listWalletMiningList(queryParams.value).then(response => {
    walletMarketList.value = response.data.records;
    total.value = response.data.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    type: null,
    channel: null,
    amount: null,
    balance: null,
    duration: null,
    status: null,
    positionStatus: null,
    startTime: null,
    startPrice: null,
    endTime: null,
    endPrice: null,
    lossOrGain: null,
    userNo: null
  };
  proxy.resetForm("walletMarketRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.current = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["walletMarketRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateWalletMarket(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addWalletMarket(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

getList();
// loading.value = false;
</script>
